package com.heima.tess4j;

import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

public class Tes4jApp {
    public static void main(String[] args) throws TesseractException {
        // 准备待识别的图片
        File file = new File("d:/img.jpeg");
        // 初始化tess4j对象
        Tesseract tesseract = new Tesseract();
        // 设置字体库所在路径
        tesseract.setDatapath("D:\\code\\javaee50");
        // 设置语言类型
        tesseract.setLanguage("chi_sim");
        // 开始识别
        String result = tesseract.doOCR(file);
        result = result.replaceAll("\\r|\\n","-").replaceAll(" ","");
        System.out.println(result);
    }
}
